using System.Collections.Generic;
using System.Linq;
using System.Text.RegularExpressions;
using ProjectEuler.Core;

namespace ProjectEuler.UI
{
    public class ProblemLoader
    {
        // this loads up any class that implements IProjectEulerProblem
        // and returns a wrapped collection of Problems
        public static IList<Problem> FindAllProblems()
        {
            var problemAssembly = typeof(IProjectEulerProblem).Assembly;

            var problemClasses = problemAssembly.GetTypes()
                .Where(type => type.Name.Contains("Problem"))
                .Where(type => !type.IsInterface)
                .Where(type => !type.Name.ToLower().Contains("test"))
                .OrderBy(type => int.Parse(Regex.Replace(type.Name, "[^0-9]", "")));

            return problemClasses.Select(problemClass => new Problem(problemClass)).ToList();
        }
    }
}